package com.situ.mall.web.config;


import com.situ.mall.common.intercetpor.Logininterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMVCConfig implements WebMvcConfigurer {


    @Value("${file.path}")
    private String filepath;
    @Value("${file.location}")
    private String fileLocation;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new Logininterceptor())
                .addPathPatterns("/cart/**")
                .addPathPatterns("/information/**")
                .addPathPatterns("/personal/**")
                .addPathPatterns("/success/**")
                .addPathPatterns("/order/**")
                .addPathPatterns("/pay/**")
                .excludePathPatterns("/cart/save");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(filepath+"**")//放图片的请求地址
                .addResourceLocations("file:" +fileLocation);//放图片的文件夹
    }

}
